package com.centling.modules.sys.manager.impl;

import com.centling.common.entity.Page;
import com.centling.common.entity.Query;
import com.centling.modules.sys.dao.SysLogMapper;
import com.centling.modules.sys.entity.SysLogEntity;
import com.centling.modules.sys.manager.SysLogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 系统日志
 *
 * @author Centling Techonlogies
 * @email xxx@centling.com
 * @url www.centling.com
 * @date 2017年8月14日 下午8:43:15
 */
@Component("sysLogManager")
public class SysLogManagerImpl implements SysLogManager {

	@Autowired
	private SysLogMapper sysLogMapper;
	@Autowired
	private MongoTemplate mongoTemplate;
	@Value(value = "${spring.data.mongodb.status}")
	private  boolean mongoStatus;
	
	@Override
	public void saveLog(SysLogEntity log) {
		long id=sysLogMapper.save(log);
		log.setId(id);
		if(mongoStatus){
			mongoTemplate.save(log);
		}
	}

	@Override
	public List<SysLogEntity> listLog(Page<SysLogEntity> page, Query query) {
		return sysLogMapper.listForPage(page, query);
	}

	@Override
	public int batchRemove(Long[] id) {
		return sysLogMapper.batchRemove(id);
	}

	@Override
	public int batchRemoveAll() {
		return sysLogMapper.batchRemoveAll();
	}

}
